<template>
        <div class>
        <el-card class="ep-card ep-search">
                <el-row :gutter="0">
                    <el-col :span="3" style="float:right">
                    <el-button type="primary"  @click="back">返回</el-button>
                    </el-col>
                   
                    <el-col :span="2" style="float:right">
                        <el-button type="success"  @click="submit">提交</el-button>
                      </el-col>
                      <el-col :span="2" style="float:right">
                          <el-button type="success"  @click="save">保存</el-button>
                        </el-col>
                </el-row>
         </el-card>
          <el-tabs type="border-card" @tab-click="changeTab">
            <el-tab-pane label="基本信息">
              <entBaseComponentDisplay ref="entBaseComponentDisplay"></entBaseComponentDisplay>
              <el-divider content-position="left">工商注册信息</el-divider>
                <entBaseGsComponentDisplay ref="entBaseGsComponentDisplay"></entBaseGsComponentDisplay>
            </el-tab-pane>
            <el-tab-pane label="人员信息">
              <entpersonComponentDisplay ref="entpersonComponentDisplay"></entpersonComponentDisplay>
            </el-tab-pane>
            <el-tab-pane label="项目受理">
              <projHandleComponent ref="projHandleComponent"></projHandleComponent>
            </el-tab-pane>
             <el-tab-pane label="材料收集" :disabled="isProjMate">
              <projMateComponent ref="projMateComponent" :projId.sync="projId"></projMateComponent>
            </el-tab-pane>
          </el-tabs>
        </div>
      </template>
      
      <script>
      export default {
        components: {
            entBaseComponentDisplay: require("@/pages/biz/ent/entDisplay/entBaseComponentDisplay.vue").default,
            entBaseGsComponentDisplay: require("@/pages/biz/ent/entDisplay/entBaseGsComponentDisplay.vue").default,
            entpersonComponentDisplay: require("@/pages/biz/ent/entDisplay/entpersonComponentDisplay.vue").default,
            projHandleComponent: require("@/pages/biz/proj/projHandle.vue").default,
            projMateComponent: require("@/pages/biz/proj/proj-mate.vue").default,
        },
        data() {
          return {
            entId:'',
            projApplyId:'',
            projId:"",
            isProjMate: true,
          };
        },
        computed: {},
        mounted() {
            if(this.$route.query.entId && this.$route.query.projApplyId){
                 this.entId=this.$route.query.entId;
                 this.projApplyId=this.$route.query.projApplyId;
            }else{
                 this.entId="";
                 this.projApplyId="";
            }
            this.init();
        },
        methods: {
          back(){
            this.$router.push({path:"/proj/projHandleList"});
          },
          init() {
            //合作银行列表
            this.$refs.entBaseComponentDisplay.init(this.entId);
            //企业人员列表
            this.$refs.entBaseGsComponentDisplay.init(this.entId);
            //其他人员列表
            this.$refs.entpersonComponentDisplay.init(this.entId);
            //项目信息
            this.$refs.projHandleComponent.init(this.projApplyId);
          },
          save(){
            let projHandle= this.$refs.projHandleComponent.getdata();
            let user=JSON.parse(sessionStorage.getItem("user"));
            projHandle.createUserId=user.id;
            projHandle.createUserName=user.realName;
            if(user.organCode){
              projHandle.organCode=user.organCode;
            }
            if(user.organId){
              projHandle.organId=user.organId;
            }
            if(user.organName){
              projHandle.organName=user.organName;
            }
            projHandle.projApplyId=this.projApplyId;
            
            this.$api.formPost( '/api/biz/project/doAcceptance',projHandle).then(res => {
                  if(res.retHead.code=="0000000"){
                        this.projId=res.retBody;
                        if (this.projId) {
                          this.isProjMate = false;
                        }
                        this.$message({
                            type: 'success',
                            message: "保存成功！"
                        });
                    }else{
                     
                        this.$message({
                            type: 'error',
                            message: res.retHead.message
                        });
                    }
            });
          },
          submit(){
            let projHandle= this.$refs.projHandleComponent.getdata();
            let user=JSON.parse(sessionStorage.getItem("user"));
            projHandle.createUserId=user.id;
            projHandle.createUserName=user.realName;
            projHandle.workflowCode="005";
            projHandle.projApplyId=this.projApplyId;
            if(!this.projId){
              this.$message({
                            type: 'error',
                            message: "请先保存，再提交",
                 });
                 return;
            }
            projHandle.id=this.projId;
            this.$api.formPost( '/api/biz/project/doStart',projHandle).then(res => {
              console.log(res);
                  if(res.retHead.code=="0000000"){
                        this.$message({
                            type: 'success',
                            message: "流程启动成功！"
                        });
                    }else{
                     
                        this.$message({
                            type: 'error',
                            message: res.retHead.message
                        });
                    }
                });
          },
          /**
           * 保存
           */
          changeTab(a, b) {
            let tabName = b.target.innerText;
            if ('材料收集' == tabName) {
              this.$refs.projMateComponent.doSaveMateList(this.projId, '1');
            }
          },
        },
        created() {}
      };
      </script>
      <style lang='scss' scoped>
      </style>